import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


public class Leetcode_1 {

    //int towsum(int nums.int target){
    //
    // }
    public int[] twoSum(int[] nums, int target) {
        int [] s = new int[2];
        Map<Integer , Integer> map = new HashMap<>();
        for(int i = 0 ; i < nums.length ; i++) {
            map.put(nums[i] , i);
            if(map.containsKey(target - nums[i])){
                s[0] = i;
                s[1] = map.get(target - nums[i]);
            }
        }
        return s;
    }

    public static void main(String[] args) {
        int[] arr = {2,7,11,15};
        //匿名内部类
        System.out.println(Arrays.toString(new Leetcode_1().twoSum(arr, 9)));
    }
}
